﻿using AiShow.Commen.Logger;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace AiShow.Commen.Encryption
{
   public class SHAEncryption
    {
        public string SHA1Encrypt(string input)
        {
            // 字符串为空
            if (string.IsNullOrWhiteSpace(input))
                return string.Empty;
            // 尝试加密
            byte[] byteArray = Encoding.UTF8.GetBytes(input);
            string ciphertext;
            try
            {
                byte[] cipherByte;
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    cipherByte = sha1.ComputeHash(byteArray);
                }
                ciphertext = Convert.ToBase64String(cipherByte);
            }
            catch (Exception ex)
            {
                //LogHelper.Error("数据加密失败", ex);
                return input;
            }
            // 返回
            return ciphertext;
        }
    }
}
